package org.skyemoon.hbase.hbasetest.common.elasticsearch;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * ES连接
 */
public class ElasticsearchConnect {

    public static Object connect(ElasticsearchTask task) {
        Object result = null;
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http"))
        );
        try {
            result = task.task(client);
            client.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
